package loengud.w11;

import java.net.*;
import java.io.*;

// A client of an HelloServer
class HelloClient {

	public static void main(String[] args) {

		args = new String[] {"localhost", "9999", "mati"};
		String hostname = args[0];
		int port = Integer.parseInt(args[1]);
		
		Socket connection = null;

		try {
			connection = new Socket(hostname, port);
		} catch (IOException ioe) {
			System.err.println("Connection failed");
			return;
		}
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					connection.getInputStream()));

			PrintWriter writer = new PrintWriter(new OutputStreamWriter(
					connection.getOutputStream()));

			writer.println(args[2]); // client name
			writer.flush();
			System.out.println("sent: " + args[2]);
			String reply = reader.readLine();
			System.out.println("Server reply: " + reply);
			connection.close();
		} catch (IOException ioe1) {
		}

	}
}